
import { memClear } from './global/clear'
import { mapAll } from './global/map'
import { globalController } from './global/controller'
import { globalGroupManager } from './global/group_manager'
import { globalLog } from './global/log'
import { errLog } from './util/log'
import { globalWarfare } from './global/warfare'

function main(){
    memClear();
    globalController.run();

    mapAll();

    if(!Memory.structures){
        Memory.structures = {};
    }

    globalGroupManager.restoreMemory();
    globalWarfare.restoreMemory();

    try{
        globalGroupManager.run();
    }catch(e){
        errLog(e);
    }

    try{
        globalWarfare.run();
    }catch(e){
        errLog(e);
    }

    globalWarfare.saveMemory();
    globalGroupManager.saveMemory();

    try{
        if(Game.cpu.bucket==10000){
            Game.cpu.generatePixel();
        }
    }catch(ignored){}

    globalLog.run();
}
module.exports.loop = ()=>{
    try{
        main();
    }catch(e){
        errLog(e);
        Game.notify(e.stack);
    }
}
